﻿/*****************************************
 * 
 *  copyright (c) by ylshen
 * 
 *  author : ylshen (syl.lucky@gmail.com)
 * 
 **************************************** */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JYStockAnalyser.Face;
using JYStockAnalyser.Model;
using JYStockAnalyser.ClientLib;

namespace JYStockAnalyser.WinUI
{
    public class StockInputer : ComboBox
    {
        public StockInputer()
        {
            m_initializeComponent();
         
        }

        private void m_initializeComponent()
        {
            this.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.AutoCompleteSource = AutoCompleteSource.ListItems;
        }

        public void BindData()
        {
            List<Stock> stocks = ClientCache.Instance.AllStocks;
            this.DataSource = stocks;
            this.Text = string.Empty;
        }

        public string SelectedStockName
        {
            get
            {
                if (this.SelectedIndex == -1)
                    return null;
                return ((Stock)this.SelectedItem).Name;
            }
        }

        public string SelectedStockNO
        {
            get
            {
                if (this.SelectedIndex == -1)
                    return this.Text.Trim();
                return ((Stock)this.SelectedItem).NO;
            }
        }
    }
}
